package cn.tansanqinger.controller.account;

import javax.servlet.http.HttpServletRequest;

import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.tansanqinger.service.account.IUserAccountService;
import cn.tansanqinger.util.PageData;

/**
 * 教师账号审核
 * @author C3H2
 * @time 2021.04
 */
@Controller
@RequestMapping("/admin/account")
public class AccountTeacherAuditController {

	@Autowired
	private IUserAccountService service;
	
	@RequestMapping("/list4")
	public ModelAndView list5(ModelAndView mv) {
		mv.setViewName("account/list4");
		return mv;
	}
	
	/**
	 * 对学生账号进行过滤，让学生账号的所有首页初始数据都可以从这里查询
	 * @param request
	 * @return
	 */
	@RequestMapping("/selectCondition4")
	public @ResponseBody String selectCondition(HttpServletRequest request) {
		PageData pd = new PageData(request);
		try {
			String keywords = pd.getString("keywords");	//关键词检索条件
			if(null != keywords && !"".equals(keywords)){
				pd.put("keywords", keywords.trim());
			}
			pd = service.selectTeacherAccount(pd,0);
			pd.put("code","0");
			pd.put("msg", "查询成功");
			return new ObjectMapper().writeValueAsString(pd);
		} catch (Exception e) {}
		return null;
	}
	
	/**
	 * 教师信息详情
	 * @param request
	 * @param mv
	 * @return
	 */
	@RequestMapping("/list4_details")
	public @ResponseBody ModelAndView list3_details(HttpServletRequest request, ModelAndView mv) {
		PageData pageData = new PageData(request);
		//对数据进行查询，所有信息不能进行修改，
		//查询报告对账号信息本身进行查询，还有操作账号的数据进行查询
		mv.addObject("user", service.selectId(pageData));
		//
		mv.setViewName("account/list4_details");
		return mv;
	}
	
	/**
	 * 驳回教师申请
	 * @param request
	 * @return
	 */
	@RequestMapping("/list4_del")
	public @ResponseBody PageData list3_del(HttpServletRequest request) {
		return service.unratify(request);
	}
	
	@RequestMapping("/ratify")
	public @ResponseBody PageData ratify(HttpServletRequest request) {
		return service.ratify(request);
	}
}
